﻿var OrderId;
var PageFlage;
var nowOrderState;
var shouyuezhuangtai;
var yuanyin;
function getPageValue() {
   
    OrderId = utils.getParam("OrderId");
    PageFlage = utils.getParam("Pageflage");
    
    

    selectBySubscribeSonId(OrderId);
}

    //根据获得的受邀信息ID 查询这条受邀信息
function selectBySubscribeSonId(Invite_id){

//alert(Invite_id);

    var selectBySubscribeSonId_Invite_URL = URL_1+"selectBySubscribeSonId"; 

    $.ajax({
        url: selectBySubscribeSonId_Invite_URL,
        type: 'GET',
        dataType: 'json',
        cache: false,
        data:{
          id:Invite_id
        },
        beforeSend: LoadFunction, //加载执行方法
        error: erryFunction, //错误执行方法
        success: succFunction //成功执行方法
    })

    function LoadFunction() {
        //$(".header1").html('加载中...');
    }

    function erryFunction() {
    alert("URL_1:"+URL_1);
    alert("Invite_id:"+Invite_id);
        window.native.toast("获取-邀约信息查询-超时");
    }

    function succFunction(JsonString) {
    
      var querenButton_obj = document.getElementById("querenButton");  
        var jvjueButton_obj = document.getElementById("jvjueButton");  
        
        json = eval(JsonString);
        if (json.code > 0) {  
         
            var objArray= json.extend.selectByPrimaryKeyWithDevice;
            var objArray_2=json.extend.selectBySubscribeSonId;
             for(var j = 0 ; j <objArray_2.length;j++){
            
              shouyuezhuangtai  =  objArray_2[j].subscribeUserStatus;
              yuanyin = objArray_2[j].subscribeResult;
              if(yuanyin==""){
              yuanyin = "已被主约人撤销";
              }
                 if(shouyuezhuangtai==0){
                    querenButton_obj.style.cssText ="display:block;" 
                    jvjueButton_obj.style.cssText ="display:block;" 
                
                }else{
                    querenButton_obj.style.cssText ="display:none;"
                    jvjueButton_obj.style.cssText ="display:none;"
                }
                
             
             }
           
            for(var i = 0 ; i <objArray.length;i++){
                //alert(objArray[i].name);             
            document.getElementById('orderUserName').innerHTML = objArray[i].subscribeUserName;
            document.getElementById('startTime').innerHTML = fmtDate(objArray[i].subscribeBeginTime,objArray[i].subscribeEndTime);
            //document.getElementById('endTime').innerHTML = fmtDate(subscribeEndTime);
            document.getElementById('orderEquipment').innerHTML = objArray[i].deviceType;
            document.getElementById('deviceNumber').innerHTML = objArray[i].deviceNumber;
            document.getElementById('equipmentPoint').innerHTML = objArray[i].devicePlace ;
document.getElementById('bbzz').innerHTML = objArray[i].subscribeRemark ;
            var htmlString=""
            if(shouyuezhuangtai ==3){
            //alert("撤消");
             htmlString+="<li class=\"mui-table-view-cell\"><img src=\"../img/chexiaoyuanyin.png\" class=\"logo\"> <span class=\"orderData\">撤销原因：</span> <span id=\"equipmentPoint\">"
             + yuanyin
             +"</span></li>"
            }
            
            }
             document.getElementById('kaka').innerHTML=htmlString;
        } else {
            window.native.toast(json.msg);
        }
    }
};


function fmtDate(stime,etime) {
    var startTime = new Date(stime);
    var endTime = new Date(etime);
    var weekStr = "星期" + "日一二三四五六".charAt(startTime.getDay());
//  var y = date.getFullYear();
    var m = startTime.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = startTime.getDate();
    d = d < 10 ? ('0' + d) : d;
    var startHour = startTime.getHours();
    startHour = startHour < 10 ? ('0' + startHour) : startHour;
    var startminute = startTime.getMinutes();
    startminute = startminute < 10 ? ('0' + startminute) : startminute;
    
    var endHour = endTime.getHours();
    endHour = endHour < 10 ? ('0' + endHour) : endHour;
    var endminute = endTime.getMinutes();
    endminute = endminute < 10 ? ('0' + endminute) : endminute;
    
    var result = m + '-' + d + ' ' +weekStr +" "+ startHour + ':' + startminute + '~'
    + endHour +":"+ endminute;
    return result;
};


function ButtonOnClick(flage) {
    if (flage == 1) { //接受按钮
        //alert("按下接受按钮");
        //alert(OrderId);

        var btnArray = ['否', '是'];
                mui.confirm('是否确认同意此次邀请', '提示', btnArray, function(e) {
                    if (e.index == 1) {
                       chuliyaoqing(1);
                    } else {
                        
                    }
                })

       // chuliyaoqing(1);
    } else if (flage == 2) { //拒绝按钮
          //alert("按下拒绝按钮");
          // alert(OrderId);
           var btnArray = ['否', '是'];
                mui.confirm('是否确认拒绝此次邀请', '提示', btnArray, function(e) {
                    if (e.index == 1) {
                       chuliyaoqing(2);
                    } else {
                        
                    }
                })
       // chuliyaoqing(2);
    }
}


//接受，拒绝邀请
function chuliyaoqing(flage) {
    //alert(flage);
   
    var updateSubscribeSonByIdForUserStatus_URL = URL_1+"updateSubscribeSonByIdForUserStatus";

    $.ajax({
        url: updateSubscribeSonByIdForUserStatus_URL,
        type: 'GET',
        dataType: 'json',
        cache: false,
        data: {
            id: OrderId,
            subscribe_user_status: flage,
            subscribe_result:""
        },
        beforeSend: LoadFunction, //加载执行方法
        error: erryFunction, //错误执行方法
        success: succFunction //成功执行方法
    })

     function LoadFunction() {
        //$(".header1").html('加载中...');
    }
    
     function erryFunction() {
      if (flage == 1) {
          	alert("请求-接受预约-超时");
      } else if (flage == 2) {
            alert("请求-拒绝预约-超时");
      }
    }
    
     function succFunction(JsonString) {

        json = eval(JsonString);
        if (json.code > 0) {
          if (flage == 1) {
               window.native.toast("已接受邀请");//代表终止状态
                  if(history.length>1){
		history.go(-2);
		}else{
		window.location.href = "MyOrder.html";
		}
          } else if (flage == 2) {
                window.native.toast("已拒绝邀请"); //代表撤销状态
                 //self.location=document.referrer;
                if(history.length>1){
		history.go(-2);
		}else{
		window.location.href = "MyOrder.html";
		}
          }
        } else {
            alert(json.msg);
        }
    }

}


   